<?php
session_start();
require_once 'dbconnect.php';
$tb_name="executives";
$uname=$_POST["name"];
//echo "usename ".$uname;
$mypwd=$_POST["pwd"];
$sql="SELECT * FROM $tb_name WHERE exe_name='$uname' AND pwd='$mypwd'";
$result=mysql_query($sql);

	
	while($row=mysql_fetch_assoc($result))
		{
		$id=$row['id'];
		$name=$row['exe_name'];
		$pass=$row['pwd'];
		}
		if(strcmp($mypwd,$pass)==0)
		{
		 $_SESSION['user']=$name;
		 $sql="select * from login_det where id='$id';";
		 $result=mysql_query($sql) or die(mysql_error());
		 while($row=mysql_fetch_assoc($result))
		 	{
			$_SESSION['last_login']=$row['last_login'];
		 	}
		 $sql="update login_det set last_login=CURRENT_TIMESTAMP where id='$id';";
         $result=mysql_query($sql); 
         if($_SESSION['user']=='admin') 
		  {
		    header("location:admin.php");
			}
			else
			header("location:user.php");
		}
		else
		{
		$msg="Wrong UserName or Password ";
		header("location:login.php?msg=".$msg);
		}
	

if($con==true) mysql_close($con) ?>